﻿using System;
using System.Collections;
using System.Collections.Generic;
using BitBenderGames;
using UnityEngine;
using Yoozoo.Modules.InnerCity.TouchCamera;

namespace com.yoozoo.gta.Extension.UGUI.ScreenOrientationEx
{
    [Serializable]
    public class MobileTouchCameraAdaptConfig
    {
        public CameraPlaneAxes CameraAxes;
        public PerspectiveZoomMode PerspectiveZoomMode;
        public float CamZoomMin;
        public float CamZoomMax;
        public float CamOverzoomMargin;
        public Quaternion BoundRotation;
        public Vector2 BoundaryMin;
        public Vector2 BoundaryMax;
        public bool CamZoomEnable;
        public float CamZoom;
        public bool EnableZoomTilt;
        public float ZoomTiltAngleMin;
        public float ZoomTiltAngleMax;
        public bool EnableZoomFov;

        
        //重写Equals方法
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return false;
            }

            MobileTouchCameraAdaptConfig other = (MobileTouchCameraAdaptConfig)obj;
          
            if (CameraAxes != other.CameraAxes
                || PerspectiveZoomMode != other.PerspectiveZoomMode
                || Math.Abs(CamZoomMin - other.CamZoomMin) > 0.001f
                || Math.Abs(CamZoomMax - other.CamZoomMax) > 0.001f
                || Math.Abs(CamOverzoomMargin - other.CamOverzoomMargin) > 0.001f
                || BoundRotation != other.BoundRotation
                || BoundaryMin != other.BoundaryMin
                || BoundaryMax != other.BoundaryMax
                || CamZoomEnable != other.CamZoomEnable
                || Math.Abs(CamZoom - other.CamZoom) > 0.001f
                || EnableZoomTilt != other.EnableZoomTilt
                || Math.Abs(ZoomTiltAngleMin - other.ZoomTiltAngleMin) > 0.001f
                || Math.Abs(ZoomTiltAngleMax - other.ZoomTiltAngleMax) > 0.001f
                || EnableZoomFov != other.EnableZoomFov)
            {
                return false;
            }

            return true;
        }
        //重写GetHashCode方法
        public override int GetHashCode()
        {
            int hash = 17;
            hash = hash * 23 + CameraAxes.GetHashCode();
            hash = hash * 23 + PerspectiveZoomMode.GetHashCode();
            hash = hash * 23 + CamZoomMin.GetHashCode();
            hash = hash * 23 + CamZoomMax.GetHashCode();
            hash = hash * 23 + CamOverzoomMargin.GetHashCode();
            hash = hash * 23 + BoundRotation.GetHashCode();
            hash = hash * 23 + BoundaryMin.GetHashCode();
            hash = hash * 23 + BoundaryMax.GetHashCode();
            hash = hash * 23 + CamZoomEnable.GetHashCode();
            hash = hash * 23 + CamZoom.GetHashCode();
            hash = hash * 23 + EnableZoomTilt.GetHashCode();
            hash = hash * 23 + ZoomTiltAngleMin.GetHashCode();
            hash = hash * 23 + ZoomTiltAngleMax.GetHashCode();
            hash = hash * 23 + EnableZoomFov.GetHashCode();
            return hash;
        }
    }
    [DisallowMultipleComponent]
    public class MobileTouchCameraAdapt : AdaptBase<MobileTouchCameraAdaptConfig, MobileTouchCamera>
    {
        protected override void CopyProperty(MobileTouchCameraAdaptConfig config) {
            base.CopyProperty(config);
            config.CameraAxes = mComponent.CameraAxes;
            config.PerspectiveZoomMode = mComponent.PerspectiveZoomMode;
            config.CamZoomMin = mComponent.CamZoomMin;
            config.CamZoomMax = mComponent.CamZoomMax;
            config.CamOverzoomMargin = mComponent.CamOverzoomMargin;
            config.BoundRotation = mComponent.BoundRotation;
            config.BoundaryMin = mComponent.BoundaryMin;
            config.BoundaryMax = mComponent.BoundaryMax;
            config.CamZoomEnable = mComponent.CamZoomEnable;
            config.CamZoom = mComponent.CamZoom;
            config.EnableZoomTilt = mComponent.EnableZoomTilt;
            config.ZoomTiltAngleMin = mComponent.ZoomTiltAngleMin;
            config.ZoomTiltAngleMax = mComponent.ZoomTiltAngleMax;
            config.EnableZoomFov = mComponent.EnableZoomFov;
        }

        protected override void ApplyConfig(MobileTouchCameraAdaptConfig config) {
            base.ApplyConfig(config);
            mComponent.CameraAxes = config.CameraAxes;
            mComponent.PerspectiveZoomMode = config.PerspectiveZoomMode;
            mComponent.CamZoomMin = config.CamZoomMin;
            mComponent.CamZoomMax = config.CamZoomMax;
            mComponent.CamOverzoomMargin = config.CamOverzoomMargin;
            mComponent.BoundRotation = config.BoundRotation;
            mComponent.BoundaryMin = config.BoundaryMin;
            mComponent.BoundaryMax = config.BoundaryMax;
            mComponent.CamZoomEnable = config.CamZoomEnable;
            mComponent.CamZoom = config.CamZoom;
            mComponent.EnableZoomTilt = config.EnableZoomTilt;
            mComponent.ZoomTiltAngleMin = config.ZoomTiltAngleMin;
            mComponent.ZoomTiltAngleMax = config.ZoomTiltAngleMax;
            mComponent.EnableZoomFov = config.EnableZoomFov;
        }
    }
}
